<cfcomponent extends="assets.calgrants.com.Base">

	<cfscript>
        import assets.calgrants.com.bo.Fund;
	</cfscript>
	
	<cffunction name="get" access="public" output="false" returntype="assets.calgrants.com.bo.Fund">
		<cfargument name="Fund_ID" type="numeric" required="true" />
		<cfscript>
			if (arguments.Fund_ID gt 0) {
				local.loadArgs = {};
				local.loadArgs.obj = new Fund();
				StructAppend(local.loadArgs, QueryToStruct(read(argumentCollection = arguments))[1]);
				return load(argumentCollection = local.loadArgs);
			} else {
				return new Fund();
			}
		</cfscript>
	</cffunction>
	
	<cffunction name="load" access="public" output="false" returntype="assets.calgrants.com.bo.Fund">
		<cfargument name="obj" type="assets.calgrants.com.bo.Fund" required="true" />
		<cfscript>
			local.obj = arguments.obj;
			if (IsDefined("arguments.Fund_ID")) {
				local.obj.setFund_ID(arguments.Fund_ID);
			}
			if (IsDefined("arguments.Program_Year")) {
				local.obj.setProgram_Year(arguments.Program_Year);
			}
			if (IsDefined("arguments.Approved")) {
				local.obj.setApproved(arguments.Approved); 
			}
			if (IsDefined("arguments.Deleted")) {
				local.obj.setDeleted(arguments.Deleted); 
			}
			if (IsDefined("arguments.Organization_ID")) {
				local.obj.setOrganization_ID(arguments.Organization_ID); 
			}
			if (IsDefined("arguments.Requested_By_ID")) {
				local.obj.setRequested_By_ID(arguments.Requested_By_ID); 
			}
			if (IsDefined("arguments.Approved_By_ID")) {
				local.obj.setApproved_By_ID(arguments.Approved_By_ID); 
			}
			if (IsDefined("arguments.Approved_Date")) {
				local.obj.setApproved_Date(arguments.Approved_Date); 
			}
			if (IsDefined("arguments.Payee_First_Name")) {
				local.obj.setPayee_First_Name(arguments.Payee_First_Name); 
			}
			if (IsDefined("arguments.Payee_Last_Name")) {
				local.obj.setPayee_Last_Name(arguments.Payee_Last_Name); 
			}
			if (IsDefined("arguments.Payee_Organization")) {
				local.obj.setPayee_Organization(arguments.Payee_Organization); 
			}
			if (IsDefined("arguments.Payee_Department")) {                             
				local.obj.setPayee_Department(arguments.Payee_Department);
			}
			if (IsDefined("arguments.Payee_Address")) {                             
				local.obj.setPayee_Address(arguments.Payee_Address);
			}
			if (IsDefined("arguments.Payee_City")) {
				local.obj.setPayee_City(arguments.Payee_City);
			}
			if (IsDefined("arguments.Payee_State")) {
				local.obj.setPayee_State(arguments.Payee_State);
			}
			if (IsDefined("arguments.Payee_Zip_Code")) {
				local.obj.setPayee_Zip_Code(arguments.Payee_Zip_Code);
			}
			if (IsDefined("arguments.Payee_Phone")) {
				local.obj.setPayee_Phone(arguments.Payee_Phone);
			}
			if (IsDefined("arguments.Payee_Email")) {
				local.obj.setPayee_Email(arguments.Payee_Email);
			}
			if (IsDefined("arguments.Payee_Tax_ID")) {
				local.obj.setPayee_Tax_ID(arguments.Payee_Tax_ID);
			}
			if (IsDefined("arguments.Signature")) {
				local.obj.setSignature(arguments.Signature); 
			}
			if (IsDefined("arguments.OAP_Value_IDs")) {
				local.obj.setOAP_Value_IDs(arguments.OAP_Value_IDs);
			}
			if (IsDefined("arguments.OAP_Other")) {
				local.obj.setOAP_Other(arguments.OAP_Other);
			}	
			if (IsDefined("arguments.Date_Created")) {
				local.obj.setDate_Created(arguments.Date_Created);
			}			
			return local.obj;
		</cfscript>
	</cffunction>

	<cffunction name="read" access="public" output="false" returntype="any">
		<cfargument name="Fund_ID" required="false" default="" />
		<cfargument name="Program_Year" required="false" default="" />
		<cfargument name="Approved" required="false" default="" />
		<cfargument name="Deleted" required="false" default="0" />
		<cfargument name="Organization_ID" required="false" default="" />
		<cfargument name="Requested_By_ID" required="false" default="" />
		<cfargument name="Approved_By_ID" required="false" default="" />
		<cfargument name="Approved_Date" required="false" default="" />
		<cfargument name="Payee_First_Name" required="false" default="" />
		<cfargument name="Payee_Last_Name" required="false" default="" />
		<cfargument name="Payee_Organization" required="false" default="" />
		<cfargument name="Payee_Department" required="false" default="" />
		<cfargument name="Payee_Address" required="false" default="" />
		<cfargument name="Payee_City" required="false" default="" />
		<cfargument name="Payee_State" required="false" default="" />
		<cfargument name="Payee_Zip_Code" required="false" default="" />
		<cfargument name="Payee_Phone" required="false" default="" />
		<cfargument name="Payee_Email" required="false" default="" />
		<cfargument name="Payee_Tax_ID" required="false" default="" />
		<cfargument name="Signature" required="false" default="" />
		<cfargument name="OAP_Value_IDs" required="false" default="" />
		<cfargument name="OAP_Other" required="false" default="" />
		<cfargument name="Date_Created" required="false" default="" />
		<cfargument name="fundIDs" required="false" default="" />
		<cfargument name="organizationIDs" required="false" default="" />
		<cfargument name="regionIDs" required="false" default="" />
		<cfset var recs = "">
		<cfstoredproc datasource="#getDatasource()#" procedure="readFund">
			<cfprocparam value="#arguments.Fund_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Fund_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Program_Year#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Program_Year)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Approved#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Approved)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Deleted#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Deleted)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Organization_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Organization_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Requested_By_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Requested_By_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Approved_By_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Approved_By_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Approved_Date#" cfsqltype="CF_SQL_TIMESTAMP" null="#IIf(Len(Trim(arguments.Approved_Date)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Payee_First_Name#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Payee_First_Name)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Payee_Last_Name#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Payee_Last_Name)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Payee_Organization#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Payee_Organization)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Payee_Department#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Payee_Department)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Payee_Address#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Payee_Address)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Payee_City#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Payee_City)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Payee_State#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Payee_State)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Payee_Zip_Code#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Payee_Zip_Code)) eq 0, true, false)#" />
			<cfprocparam value="#formatPhone(arguments.Payee_Phone)#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Payee_Phone)) eq 0, true, false)#" />
			<cfprocparam value="#LCase(arguments.Payee_Email)#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Payee_Email)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Payee_Tax_ID#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Payee_Tax_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Signature#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Signature)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.OAP_Value_IDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.OAP_Value_IDs)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.OAP_Other#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.OAP_Other)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Date_Created#" cfsqltype="CF_SQL_TIMESTAMP" null="#IIf(Len(Trim(arguments.Date_Created)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.fundIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.fundIDs)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.organizationIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.organizationIDs)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.regionIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.regionIDs)) eq 0, true, false)#" />
			<cfprocresult name="recs" />
		</cfstoredproc>
		<cfreturn recs />
	</cffunction>

	<cffunction name="save" access="public" output="false" returntype="any">
		<cfargument name="fund" required="true" type="assets.calgrants.com.bo.Fund" />
		<cfstoredproc datasource="#getDatasource()#" procedure="saveFund">
			<cfprocparam value="#fund.getFund_ID()#" cfsqltype="CF_SQL_INTEGER" variable="id" type="inout" null="false" />
			<cfprocparam value="#fund.getProgram_Year()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#fund.getApproved()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#fund.getDeleted()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#fund.getOrganization_ID()#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="#fund.getRequested_By_ID()#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="#fund.getApproved_By_ID()#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="#fund.getApproved_Date()#" cfsqltype="CF_SQL_TIMESTAMP" null="#IIf(Len(Trim(fund.getApproved_Date())) eq 0, true, false)#" />
			<cfprocparam value="#fund.getPayee_First_Name()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#fund.getPayee_Last_Name()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#fund.getPayee_Organization()#" cfsqltype="CF_SQL_VARCHAR" />
			<cfprocparam value="#fund.getPayee_Department()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#fund.getPayee_Address()#" cfsqltype="CF_SQL_VARCHAR" />
			<cfprocparam value="#fund.getPayee_City()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="CA" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#fund.getPayee_Zip_Code()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#formatPhone(fund.getPayee_Phone())#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#LCase(fund.getPayee_Email())#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#fund.getPayee_Tax_ID()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(fund.getPayee_Tax_ID())) eq 0, true, false)#" />
			<cfprocparam value="#fund.getSignature()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#fund.getOAP_Value_IDs()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(fund.getOAP_Value_IDs())) eq 0, true, false)#" />
			<cfprocparam value="#fund.getOAP_Other()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(fund.getOAP_Other())) eq 0, true, false)#" />
		</cfstoredproc>
		<cfreturn id />
	</cffunction>

	<cffunction name="destroy" access="public" output="false" returntype="any">
		<cfargument name="Fund_ID" required="true" />
		<cfstoredproc datasource="#getDatasource()#" procedure="destroyFund">
			<cfprocparam value="#arguments.Fund_ID#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="true" cfsqltype="CF_SQL_BIT" null="false" />
		</cfstoredproc>
		<cfreturn true />
	</cffunction>

</cfcomponent>

